import * as types from '../constants/ActionTypes';

export default function products(state = [], action = {}) {
    const {
        type, payload
    } = action;

    switch (type) {
        //============================================================
        //获取指定日盘前股讯
        //============================================================
        case types.FETCH_RECOMMEND:
            return { ...state, ...payload };

        case types.FETCH_RECOMMEND_SUCCESS:
            let todaySuccessInfo = {
                recommend_status : 1,
                message : "获取盘前股讯成功",
                today : payload.results
            };

            return { ...state, ...todaySuccessInfo };

        case types.FETCH_RECOMMEND_FAILURE:
            let todayFailureInfo = {
                recommend_status : -1,
                message : "获取盘前股讯失败",
                today : []
            };

            return { ...state, ...todayFailureInfo};

        //============================================================
        //获取上交易日盘前股讯
        //============================================================
        case types.FETCH_LAST_RECOMMEND:
            return { ...state , ...payload};

        case types.FETCH_LAST_RECOMMEND_SUCCESS:
            let lastSuccessInfo = {
                recommend_last_status : 1,
                message : "获取昨日盘前股讯成功",
                last : payload.results
            };

            return {...state, ...lastSuccessInfo};

        case types.FETCH_LAST_RECOMMEND_FAILURE:
            let historyFailureInfo = {
                recommend_last_status : -1,
                message : "获取昨日盘前股讯失败",
                last : []
            };

            return { ...state, ...lastFailureInfo};

        //============================================================
        //盘前股讯关注
        //============================================================
        case types.SIGN_RECOMMEND:
            return { ...state, ...payload };
        case types.SIGN_RECOMMEND_SUCCESS:

            let signSuccessInfo = {
                recommend_sign_status : 1,
                message : "订阅成功"
            };
            return {
               ...state,
               ...signSuccessInfo
            };
        case types.SIGN_RECOMMEND_FAILURE:
        
            let signFailureInfo = {
                recommend_sign_status : -1,
                message: payload.message||'网络连接失败'
            };
            return {
               ...state,
               ...signFailureInfo
            };
        //============================================================
        //盘前股讯取消关注
        //============================================================
        case types.UNSIGN_RECOMMEND:
            return { ...state, ...payload };
        case types.UNSIGN_RECOMMEND_SUCCESS:
            let unsignSuccessInfo = {
                recommend_unsign_status : 1,
                message : "取消订阅成功"
            };
            return {
               ...state,
               ...unsignSuccessInfo
            };
        case types.UNSIGN_RECOMMEND_FAILURE:
            let unsignFailureInfo = {
                recommend_unsign_status : -1,
                message: payload.message||'网络连接失败'
            };
            return {
               ...state,
               ...unsignFailureInfo
            };
        
        default:
            return state;
    }
}